package com.mareas.web.jsf.view;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mareas.web.model.Cliente;
import com.mareas.web.service.ClienteService;

@Component("listClienteView")
@ManagedBean
@RequestScoped
public class ListClienteView implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = -2414982654514242280L;

	@Autowired
	private ClienteService clienteService;

	private int page = 1;
	private int currentClienteIndex;
	private Cliente editedCliente;
	private Cliente deletedCliente;

	public ListClienteView() {
		super();
	}

	public Cliente getNewCliente() {
		return clienteService.newCliente();
	}

	public void remove() {
		clienteService.remove(deletedCliente);
	}

	public void store() {
		if(editedCliente.getClienteId() != null) {
			clienteService.update(editedCliente);
		} else {
			clienteService.persist(editedCliente);
		}
	}

	public List<Cliente> getClientes() {
		return clienteService.getClientes();
	}

	public ClienteService getClienteService() {
		return clienteService;
	}

	public void setClienteService(ClienteService clienteService) {
		this.clienteService = clienteService;
	}

	public Cliente getEditedCliente() {
		return editedCliente;
	}

	public void setEditedCliente(Cliente editedCliente) {
		this.editedCliente = editedCliente;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getCurrentClienteIndex() {
		return currentClienteIndex;
	}

	public void setCurrentClienteIndex(int currentClienteIndex) {
		this.currentClienteIndex = currentClienteIndex;
	}

	public Cliente getDeletedCliente() {
		return deletedCliente;
	}

	public void setDeletedCliente(Cliente deletedCliente) {
		this.deletedCliente = deletedCliente;
	}

}
